# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-certificate_authority
pkgver=1.1.0
pkgrel=2
pkgdesc='Ruby gem for managing the core functions outlined in RFC-3280 for PKI'
arch=(any)
url='https://github.com/cchandler/certificate_authority'
license=(MIT)
depends=(ruby)
makedepends=(ruby-pry ruby-rake ruby-rspec)
options=(!emptydirs)
source=(https://github.com/cchandler/certificate_authority/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('b6cc0d136d8f7ebdaa796c62e7eb8e755f2e409616c55990a8bde6f255154890')

prepare() {
  cd certificate_authority-$pkgver
  sed -e '/[cC]overalls/d' -e '/rubocop/d' -r -e 's|git ls-files -z|find . -type f -not -path "*/\.git/*" -printf "%P\\\\0"|' \
      -i certificate_authority.gemspec Rakefile spec/spec_helper.rb
  rm Gemfile.lock
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd certificate_authority-$pkgver
  rake build
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    pkg/certificate_authority-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd certificate_authority-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake spec
}

package() {
  cd certificate_authority-$pkgver
  cp -a tmp_install/* "$pkgdir"/
}
